package com.coffee.controller;

import com.coffee.entity.Category;
import com.coffee.entity.R;
import com.coffee.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 咖啡分类控制器
 */
@RestController
@RequestMapping("/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    /**
     * 查询分类列表
     * @return
     */
    @GetMapping("list")
    public R<List<Category>> list() {
        return R.success(categoryService.list());
    }

    /**
     * 增加分类
     * @param category
     * @return
     */
    @PostMapping("/add")
    public R add(@RequestBody Category category) {
        categoryService.add(category);
        return R.success(category);
    }

    /**
     * 修改分类
     * @param category
     * @return
     */
    @PostMapping("edit")
    public R edit(@RequestBody Category category) {
        categoryService.edit(category);
        return R.success(category);
    }

    /**
     * 删除分类
     * @param category
     * @return
     */
    @PostMapping("delete")
    public R delete(@RequestBody Category category) {
        categoryService.delete(category);
        return R.success(category);
    }
}
